From f70917537de06598584d6c981ea4029612cfe02f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 19 Jan 2016 12:06:58 -0800 Subject: [PATCH] Fix update --precise with the registry source There was a previous bug where if any crate's name was the start of the crate being updated that the crate wouldn't resolve at all, and this fixes the prefix checking error bug. cc #2293 --- src/cargo/sources/registry.rs | 3 ++- tests/test_cargo_registry.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index 7a7822a67..438901d8e 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -505,7 +505,8 @@ impl<'cfg> Registry for RegistrySource<'cfg> { // version requested (agument to `--precise`). summaries.retain(|s| { match self.source_id.precise() { - Some(p) if p.starts_with(dep.name()) => { + Some(p) if p.starts_with(dep.name()) && + p[dep.name().len()..].starts_with("=") => { let vers = &p[dep.name().len() + 1..]; s.version().to_string() == vers } diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index e9a452875..b9c986519 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -932,3 +932,27 @@ test!(bundled_crate_in_registry { assert_that(p.cargo("run"), execs().with_status(0)); }); + +test!(update_same_prefix_oh_my_how_was_this_a_bug { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "ugh" + version = "0.5.0" + authors = [] + + [dependencies] + foo = "0.1" + "#) + .file("src/main.rs", "fn main() {}"); + p.build(); + + Package::new("foobar", "0.2.0").publish(); + Package::new("foo", "0.1.0") + .dep("foobar", "0.2.0") + .publish(); + + assert_that(p.cargo("generate-lockfile"), execs().with_status(0)); + assert_that(p.cargo("update").arg("-pfoobar").arg("--precise=0.2.0"), + execs().with_status(0)); +}); -- 2.30.2